import request from '@/utils/request'
import apis from './'

/**
 * 合同列表
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getList (parameter) {
  return request({
    url: apis.ContractList,
    method: 'get',
    params: parameter
  })
}

/**
 * 添加客户，获取信息
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getAddInfo (parameter) {
  return request({
    url: `${apis.AddCon}?customer_id=${parameter.customer_id}&part=${parameter.part}`,
    method: 'get'
  })
}

export function saveAddInfo (data) {
  return request({
    url: `${apis.AddCon}?customer_id=${data.customer_id}&part=${data.part}`,
    method: 'post',
    data: data
  })
}

/**
 * 编辑合同，获取信息
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getEdit (parameter) {
  return request({
    url: `${apis.EditCon}?contract_id=${parameter.contract_id}&part=${parameter.part}`,
    method: 'get'
  })
}

/**
 * 保存编辑
 * @param data
 * @returns {AxiosPromise}
 */
export function saveEdit (data) {
  return request({
    url: `${apis.EditCon}?contract_id=${data.contract_id}&part=${data.part}`,
    method: 'post',
    data: data
  })
}

/**
 * 获取编辑合同状态
 * @param contractId
 * @returns {AxiosPromise}
 */
export function getStatus (contractId) {
  return request({
    url: `${apis.ConStatus}?contract_id=${contractId}`,
    method: 'get'
  })
}

/**
 * 保存编辑合同状态
 * @param contractId
 * @returns {AxiosPromise}
 */
export function editStatus (contractId) {
  return request({
    url: `${apis.ConStatus}?contract_id=${contractId}`,
    method: 'post'
  })
}

/**
 * 删除合同
 * @param id
 * @returns {AxiosPromise}
 */
export function delContract (id) {
  return request({
    url: `${apis.DelContract}?contract_id=${id}`,
    method: 'get'
  })
}

/**
 * 获取打款信息
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getPayment (parameter) {
  return request({
    url: apis.GetPayList,
    method: 'get',
    params: parameter
  })
}

/**
 * 添加打款
 * @param id
 * @returns {AxiosPromise}
 */
export function getAddPay (id) {
  return request({
    url: `${apis.AddPay}?contract_id=${id}`,
    method: 'get'
  })
}

export function addPay (data) {
  return request({
    url: `${apis.AddPay}?contract_id=${data.contract_id}`,
    method: 'post',
    data: data
  })
}

export function getEditPay (parameter) {
  return request({
    url: apis.EditPay,
    method: 'get',
    params: parameter
  })
}

export function postEditPay (data) {
  return request({
    url: `${apis.EditPay}?payment_id=${data.payment_id}&contract_id=${data.contract_id}`,
    method: 'post',
    data: data
  })
}

/**
 * 删除打款信息
 * @param parameter
 * @returns {AxiosPromise}
 */
export function delPayment (parameter) {
  return request({
    url: apis.DelPayment,
    method: 'get',
    params: parameter
  })
}

/**
 * 获取可选业务
 * @returns {AxiosPromise}
 */
export function getBusiness () {
  return request({
    url: apis.AddBusiness,
    method: 'get'
  })
}

/**
 * 获取已选业务
 * @param parameter
 * @returns {AxiosPromise}
 */
export function getSelectedBus (parameter) {
  return request({
    url: apis.GetSelectedBus,
    method: 'get',
    params: parameter
  })
}

export function getSelectedBus2 (parameter) {
  return request({
    url: apis.GetSelectedBus2,
    method: 'get',
    params: parameter
  })
}

/**
 * 删除已选业务
 * @param parameter
 * @returns {AxiosPromise}
 */
export function delSelectedBus (parameter) {
  return request({
    url: apis.DelSelectedBus,
    method: 'get',
    params: parameter
  })
}

export function delSelectedBus2 (parameter) {
  return request({
    url: apis.DelSelectedBus2,
    method: 'get',
    params: parameter
  })
}

export function addSelectedBus (data) {
  return request({
    url: apis.AddBusiness,
    method: 'post',
    data: data
  })
}

export function addSelectBusiness2 (data) {
  return request({
    url: apis.AddBusiness2,
    method: 'post',
    data: data
  })
}

export function history (parameter) {
  return request({
    url: apis.History,
    method: 'get',
    params: parameter
  })
}

export function log (parameter) {
  return request({
    url: apis.Transfer,
    method: 'get',
    params: parameter
  })
}

export function getAddressList (parameter) {
  return request({
    url: apis.AddressList,
    method: 'get',
    params: parameter
  })
}

export function getAddress (id) {
  return request({
    url: `${apis.AddAddress}?contract_id=${id}`,
    method: 'get'
  })
}

export function addAddress (data) {
  return request({
    url: `${apis.AddAddress}?contract_id=${data.contract_id}`,
    method: 'post',
    data: data
  })
}

export function delAddress (parameter) {
  return request({
    url: apis.DelAddress,
    method: 'get',
    params: parameter
  })
}

export function getEditAddr (parameter) {
  return request({
    url: apis.EditAddr,
    method: 'get',
    params: parameter
  })
}

export function editAddr (data) {
  return request({
    url: `${apis.EditAddr}?contract_id=${data.contract_id}&id=${data.id}`,
    method: 'post',
    data: data
  })
}

export function transfer (parameter) {
  return request({
    url: apis.Transfer,
    method: 'get',
    params: parameter
  })
}

/**
 * 退款合同列表
 * @param parameter
 * @returns {AxiosPromise}
 */
export function refundList (parameter) {
  return request({
    url: apis.RefundList,
    method: 'get',
    params: parameter
  })
}

export function refundList2 (parameter) {
  return request({
    url: apis.RefundList2,
    method: 'get',
    params: parameter
  })
}

export function refundDetail (id) {
  return request({
    url: `${apis.RefundDetail}?refund_id=${id}`,
    method: 'get'
  })
}

export function delRefund (cid, rid) {
  return request({
    url: `${apis.DelRefund}?contract_id=${cid}&refund_id=${rid}`,
    method: 'get'
  })
}

export function getRefundEdit (cid, rid) {
  return request({
    url: `${apis.EditRefund}?contract_id=${cid}&refund_id=${rid}`,
    method: 'get'
  })
}

export function postRefundEdit (data) {
  return request({
    url: `${apis.EditRefund}?contract_id=${data.contract_id}&refund_id=${data.refund_id}`,
    method: 'post',
    data: data
  })
}

export function getAddRefund (cid) {
  return request({
    url: `${apis.AddRefund}?contract_id=${cid}`,
    method: 'get'
  })
}

export function postAddRefund (data) {
  return request({
    url: `${apis.AddRefund}?contract_id=${data.contract_id}`,
    method: 'post',
    data: data
  })
}

export function getEditRefund (cid, rid) {
  return request({
    url: `${apis.EditRefund}?contract_id=${cid}&refund_id=${rid}`,
    method: 'get'
  })
}

export function postEditRefund (data) {
  return request({
    url: `${apis.EditRefund}?contract_id=${data.contract_id}&&refund_id=${data.refund_id}`,
    method: 'post',
    data: data
  })
}

export function getAddInvoice (parameter) {
  return request({
    url: apis.GetInvoice,
    method: 'get',
    params: parameter
  })
}

export function postAddInvoice (data, parameter) {
  return request({
    url: apis.GetInvoice,
    method: 'post',
    params: parameter,
    data: data
  })
}

export function getEditInvoice (id) {
  return request({
    url: `${apis.EditInvoice}?invoice_id=${id}`,
    method: 'get'
  })
}

export function postEditInvoice (data, id) {
  return request({
    url: `${apis.EditInvoice}?invoice_id=${id}`,
    method: 'post',
    data: data
  })
}

export function getInvoiceList (parameter) {
  return request({
    url: apis.InvoiceList,
    method: 'get',
    params: parameter
  })
}

export function getPhoneArray (phone) {
  return request({
    url: `${apis.GetPhoneArray}?phone=${phone}`,
    method: 'get'
  })
}

export function getAddItem (id) {
  return request({
    url: `${apis.AddItem}?business_id=${id}`,
    method: 'get'
  })
}

export function getBusinessCache (id) {
  return request({
    url: `${apis.BusinessCache}cache_id=${id}`,
    method: 'get'
  })
}

export function postBusinessCache (data) {
  return request({
    url: apis.BusinessCache,
    method: 'post',
    data: data
  })
}

export function getCacheList (parameter) {
  return request({
    url: `${apis.CacheList}?filter[contract_id]=${parameter.contract_id}`,
    method: 'get',
    params: parameter
  })
}

export function delCache (tid, bid, id) {
  return request({
    url: `${apis.DelCache}?cache_id=${id}&contract_id=${tid}&business_id=${bid}`,
    method: 'get'
  })
}

export function getAddExtCache (parameter) {
  return request({
    url: apis.AddExtCache,
    method: 'get',
    params: parameter
  })
}

export function postAddExtCache (data, id, ecid) {
  return request({
    url: `${apis.AddExtCache}?cache_id=${id}&ext_cache_id=${ecid}`,
    method: 'post',
    data: data
  })
}

export function delExtCache (id) {
  return request({
    url: `${apis.DelExtCache}?cache_id=${id}`,
    method: 'get'
  })
}

export function delAllCache (id) {
  return request({
    url: `${apis.DelAllCache}?contract_id=${id}`,
    method: 'get'
  })
}

export function getCacheView (id) {
  return request({
    url: `${apis.GetExtCache}?ext_cache_id=${id}`,
    method: 'get'
  })
}

export function getEditPrice (cid, bid) {
  return request({
    url: `${apis.EditPrice}?contract_id=${cid}&cb_id=${bid}`,
    method: 'get'
  })
}

export function postEditPrice (data, parameter) {
  return request({
    url: apis.EditPrice,
    method: 'post',
    params: parameter,
    data: data
  })
}

export function getSendSms (id) {
  return request({
    url: `${apis.ContractSms}?contract_id=${id}`,
    method: 'get'
  })
}

export function postSendSms (data) {
  return request({
    url: apis.ContractSms,
    method: 'post',
    data: data
  })
}
